package com.secondriver.url.match;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.secondriver.url.filter.match.URLPatternMatch;
import com.secondriver.url.filter.match.groovy.DefalutURLPatternMatch;

class TestDefaultURLPatternMatch {

	def static urls=['/login/index.jsp', '/user/admin', '/home', '/index', "index.jsp"] as HashSet;

	def static URLPatternMatch match;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		match=new DefalutURLPatternMatch();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Test
	public void test11(){
		assertFalse(DefalutURLPatternMatch.isEmpty("/abc"));
	}

	@Test
	public void test12(){
		assertTrue(DefalutURLPatternMatch.isEmpty(null));
	}

	@Test
	public void test13(){
		assertTrue(DefalutURLPatternMatch.isEmpty(""));
	}

	@Test
	public void test21(){
		String url="abc/**/def/?xy/*.jsp";
		assertTrue(["abc", "**", "def", "?xy", "*.jsp"]==DefalutURLPatternMatch.splitUrlToParts(url));
	}

	@Test
	public void test22(){
		String url="/abc/**/def/?xy/*.jsp/";
		assertTrue(["abc", "**", "def", "?xy", "*.jsp"]==DefalutURLPatternMatch.splitUrlToParts(url));
	}

	@Test
	public void test23(){
		String url="/abc//**/def/ /?xy/*.jsp/''/";
		assertTrue(["abc", "**", "def", "?xy", "*.jsp", '\'\'']==DefalutURLPatternMatch.splitUrlToParts(url));
	}


	@Test
	public void test31(){
		String url="index.jsp";
		assertTrue("/index.jsp"==DefalutURLPatternMatch.fixedUrlPrefix(url));
	}

	@Test
	public void test32(){
		String url="/index.jsp";
		assertTrue("/index.jsp"==DefalutURLPatternMatch.fixedUrlPrefix(url));
	}

	@Test
	public void testDefault1(){
		assertTrue(match.isPass("/index", urls));
	}

	@Test
	public void testDefault2(){
		assertTrue(match.isPass("/login/index.jsp", urls));
	}

	@Test
	public void testDefault3(){
		assertFalse(match.isPass("/", urls));
	}

	@Test
	public void testDafault4(){
		assertTrue(match.isPass("index", urls));
	}

	@Test
	public void testDefault5(){
		assertTrue(match.isPass("index.jsp", urls));
	}
}
